﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using MiragePWF.Common.Validation;
using Wolfut.MirageEE.Domain.CommonUtilities;

namespace Wolfut.MirageEE.UI.UICommonUtilities
{
    public class ClientExceptionHandler //: ExceptionHandler
    {
        private ExceptionRender MyExceptionRender;

        public ClientExceptionHandler(ExceptionRender objExceptionRender)
        {
            MyExceptionRender = objExceptionRender;
        }
        public ClientExceptionHandler()
        {
        }
        //public override void Initialize(ConfigurationView configurationView)
        //{
        //}

        public  bool HandleException(Exception exception, string policyName, Guid handlingInstanceId)
        {
            if (exception is MirageValidationException)
            {
                string[] mesages  = (exception as MirageValidationException).ValidationErrorMessages;
                StringBuilder builder = new StringBuilder();
                foreach(string message in mesages)
                {
                    builder.AppendLine(message);
                }

                CustomerShowMessage.ShowErrorMessage(builder.ToString());
                return true;
            }

            else
            {
                MyExceptionRender.WriteToClient(exception.Message);
                return false;
            }
             

        }
    }
    public class WebClientExceptionHandler : ClientExceptionHandler
    {
        public WebClientExceptionHandler()
            : base(new ExceptionRender(Constant.RenderType.WEB))
        {
        }

    }
    public class WinClientExceptionHandler : ClientExceptionHandler
    {
        public WinClientExceptionHandler()
            : base(new ExceptionRender(Constant.RenderType.WIN))
        {

        }

    }
}